		var retentDayArray=[];
          var editIndex = undefined;
		  var mark = $('#mark').val();
          $('#tt').edatagrid({

           	url:"/channelconfig/retentExecTimesList?mark="+mark,
            onClickRow: function(index){
            	 if(mark==''){return};
                 if(index!=editIndex){
                     editIndex = index;
                  }
             },
             onLoadSuccess:function(data){
             	$(this).datagrid('enableDnd');
             	retentDayArray=[];

             	if(data.rows.length==0){
             		if(mark==''){
             			 $('#tt').datagrid({
 	                        url:'',
 	                        data:''
             			 }); 
             		}else{

                   	 var data1 = [
                	              {'mark':mark,'execTimes':'1','allRetentRate':'100'},
                	              {'mark':mark,'execTimes':'2','allRetentRate':''},
                	              {'mark':mark,'execTimes':'3','allRetentRate':''},
                	              {'mark':mark,'execTimes':'4','allRetentRate':''},
                	              {'mark':mark,'execTimes':'5','allRetentRate':''},
                	              {'mark':mark,'execTimes':'6','allRetentRate':''},
                	              {'mark':mark,'execTimes':'7','allRetentRate':''}

                	          ];
             			$('#tt').datagrid({
 	                        url:'',
 	                        data:data1
             			 }); 
             			
             		}
            	}else{
                  	$.each(data.rows,function(index,mod){
                		retentDayArray.push(mod.retentDay)
                	})
            	}
             },
             onBeforeSave:function(index){
            	 var execTimesVal=$("td[field='execTimes'] input").val();
            	 var allRetentRate=$("td[field='allRetentRate'] input").val();

            	 if(execTimesVal==''){
            		 return false;
            	 }

            	 if(allRetentRate==''){
            		 return false;
            	 }
             }
          });
         //查询
         function doSearch(){
          	$('#tt').edatagrid({
          		url:"/channelconfig/retentExecTimesList?mark="+$('#mark').val()});
         }
         //添加
         function addRow(){
         	var markId=$('#mark').val();
         	if(markId==''){return}
         	var file='/resources/js/easyui/datagrid-dnd.js';
         	$('#tt').edatagrid('appendRow', {
         		mark:markId,
				execTimes:'',
				allRetentRate:''
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
		    var markId=$('#mark').val();
         	if(markId==''){return}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow')
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
		  		if(mod.execTimes===''||mod.allRetentRate==0){
		  		}else{
		  			var	array={};
			  		array={execTimes:mod.execTimes,allRetentRate:mod.allRetentRate,mark:mod.mark};
			  		newRow.push(array);
			  		arrayLen=newRow.length;
		  		}
		  		
		  	})
		  
		  	$.ajax({
		  		url:'/channelconfig/saveRetentExecTimes',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	})
            
        }
        //删除
        function remove(){
		  	var rows = $('#tt').edatagrid('getChecked');
		  	var arr = [];
		  	for (var i=0;i<rows.length;i++) {
		  		var retentTimeConfig = {};
		  		retentTimeConfig['execTimes'] = rows[i].execTimes;
				retentTimeConfig['mark'] = rows[i].mark;
				retentTimeConfig['allRetentRate'] = rows[i].allRetentRate;
		  		arr.push(retentTimeConfig)
		  	}
		  	
		  	$.ajax({
		  		headers: {
	                'Accept': 'application/json',
	                'Content-Type': 'application/json'
	            },
		  		url:'/channelconfig/batchDeleteTimes',
		  		type:'POST',
		  		data: JSON.stringify(arr),
		  		async: true,
	            dataType: "json",
		  		success:function(){
	  				jQuery.messager.alert('提示:','删除成功!'); 
		  			doSearch();
		  		}
		  	})
        }
        
        //全选
        function selectAll(){
        	 $('#tt').datagrid('selectAll');
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='allRetentRate'] input","td[field='exetimes'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})

		$(document).on("keyup afterpaste","td[field='allRetentRate'] input",function(e){
			this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
			this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
			this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
			this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
			if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
				this.value= parseFloat(this.value);
			}
			if(this.value>100){
				this.value = 100;
			}
		})
		
		$(document).on('blur', '.datagrid-view td[field=execTimes] input', function(){
			var inputVal=this.value;
			$.each(retentDayArray,function(index,mod){
				if(mod==inputVal){
					inputVal='';
					jQuery.messager.alert('提示:','留存天数不能重复!');	
				}
			})
			$(this).val(inputVal);
		});
  
	  
		